package hangban.com.maochang.test;



import hangban.com.maochang.impl.*;
import hangban.com.maochang.pojo.AirInfo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Scanner;


public class AirInfotest {
    public static void main(String[] args) throws Exception {
        AirInfoAllDaoImpl allDao = new AirInfoAllDaoImpl();
        UpdateAirInfoDaoImpl updateAirInfoDao=new UpdateAirInfoDaoImpl();
        DeleteAirInfoDaoImpl deleteAirInfoDao=new DeleteAirInfoDaoImpl();
        AirInfoDateDaoImpl airInfodateDao=new AirInfoDateDaoImpl();
        AirInfoDiDaoImpl airInfoDiDao=new AirInfoDiDaoImpl();

        Scanner input = new Scanner(System.in);
        boolean flag=true;
        do {
            System.out.println("请选择操作(1.列出所有航班 2.按起飞时间查询 3.按目的地查询 4.删除航班 5.更新航班 6.离开系统)");
            int demo = input.nextInt();
            switch (demo) {
                case 1:
                    System.out.println("dfakdlflaskdfjakl");
                    List<AirInfo> selectAll = allDao.getSelectAll();
//                    System.out.println(selectAll.toString());
                    selectAll.forEach(v->{
                        System.out.println(v.getId()+"-"+v.getHangcard()+"-"+v.getDatefei()+v.getMudi());
                    });

                    break;
                case 2:
                    System.out.println("请输入要查询的日期");
                    String r=input.next();
                    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
                    Date parse = simpleDateFormat.parse(r);
                    List<AirInfo> selectri = airInfodateDao.getSelect(parse);
                    selectri.forEach(i->{
                        System.out.println(i.getId()+"-"+i.getHangcard()+"-"+i.getMudi()+"-"+i.getDatefei());
                    });
                    break;
                case 3:
                    System.out.println("请输入要查询的目的地");
                    String mudi=input.next();
                    List<AirInfo> selectdi = airInfoDiDao.getSelectdi(mudi);
                    selectdi.forEach(i->{
                        System.out.println(i.getId()+"-"+i.getHangcard()+"-"+i.getMudi()+"-"+i.getDatefei());
                    });
                    break;
                case 4:
                    System.out.println("请输入你要删除的航班id");
                    int hid=input.nextInt();
                    deleteAirInfoDao.deleteAirInfo(hid);
                    break;
                case 5:
                    System.out.println("请输入要更新的航班id");
                    int id=input.nextInt();
                    System.out.println("请输入新的航班号");
                    int hangcard=input.nextInt();
                    System.out.println("请输入新的目的地");
                    String mmd=input.next();
                    System.out.println("请输入新的起飞日期");
                    String ri=input.next();
                    SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                    Date date=null;
                    try {
                        date = dateFormat.parse(ri);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    updateAirInfoDao.updateAirInfo(id,hangcard,mmd,date);
                    break;
                case 6:
                    System.out.println("退出航班系统");
                        flag=false;
                    break;
            }
        } while (flag);
    }
}
